package com.cynen.p42u.service.impl;

import com.cynen.p42u.dao.JavDictDao;
import com.cynen.p42u.pojo.JavDict;
import com.cynen.p42u.service.JavDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class JavDictServiceImpl implements JavDictService {

    @Autowired
    private JavDictDao javDictDao;

    @Override
    public void save(JavDict javDict) {
        javDictDao.save(javDict);
    }

    @Override
    public List findAll(JavDict javDict) {
        Example<JavDict> example = Example.of(javDict);
        List<JavDict> all = javDictDao.findAll(example);
        return all;
    }

    @Override
    public List findAl() {
        return javDictDao.findAll();
    }

    @Override
    public void update(JavDict javDict) {
        Optional<JavDict> dictDaoById = javDictDao.findById(javDict.getId());
        if (dictDaoById.isPresent()){
            javDictDao.save(javDict);
        }
    }
}
